#!Shot: 24032706
# !Signal: HF_sxr: Averaged(200)
# !Calibrations applied (if any)
# !Program version 442; Export date: 26.04.2024 (13:25:51)

import matplotlib.pyplot as plt
import numpy as np
import calculateradiation as radiation
import libraries.filereader as filereader

with open('HF_sxr.txt', 'r') as file:
    fileData = filereader.interpolateFromFile(file)
    data = lambda x: fileData(x) / 1.9

X_ = np.linspace(40, 90, 50)
a = 0.113
normalize = lambda x: data(x) - data(8)
to_V_from_mV = lambda x: normalize(x) / 1000
Zeff = lambda x: a * to_V_from_mV(x) / radiation.calculateRadiation(x)

# x = 90
# ZeffFile = open('24032706-Zeff-by-time.txt', 'a')
# ZeffFile.write(str(x) + ' ' + str(Zeff(x)) + '\n')
# ZeffFile.close()
Y_ = []
for x in X_:
    # ZeffFile.write(str(x) + ' ' + str(Zeff(x)) + '\n')
    Y_.append(Zeff(x))
plt.plot(X_, Y_)
plt.title("Zeff")
plt.xlabel("time, ms")
plt.ylabel("Y")

plt.savefig('Zeff.png')
plt.show()
